<?php
namespace App\Http\Controllers\Business\Admin\Salesman;

use App\Http\Controllers\Business\Admin\Shop\ShopManagement;
use App\Models\AdminUser;
use App\Models\Order;
use App\Models\Shop;
use App\Models\ShopUser;
use App\Models\User;
use App\Models\ShopSalesman;
use App\Models\ShopSalesmanDetail;
use App\Models\ShopSalesmanWithdrawal;
use App\Models\ShopSalesmanLog;
use Auth;
use Exception;

class ShopSalesmanManagement{

    //地推商家列表
    public static function shopSalesmanList($cityid, $type='%', $status='%',$search='', $perpage=1000) {
        if(!$cityid) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        if($cityid == 1) {
            //南昌总部
            if ($search) {
                $GLOBALS['search'] = $search;
                $data = ShopSalesman::where('shop_salesman.type', 'like', $type)
                    ->where('shop_salesman.status', 'like', $status)
                    ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
                    ->where('shops.cityid', $cityid)
                    ->where(function ($query) {
                        $query->orWhere('shops.code', 'like', '%' . $GLOBALS . '%')
                            ->orwhere('shops.name', 'like', '%' . $GLOBALS . '%');
                    })
                    ->orderBy('shop_salesman.created_at', 'desc')
                    ->select('shop_salesman.id as shopsalesmanid', 'shops.id as shopid', 'shops.code', 'shops.parentmobile', 'shops.name as shopname', 'shops.address', 'shops.qrcode', 'shop_salesman.adminname', 'shop_salesman.type', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime', 'shop_salesman.commonregisternum', 'shop_salesman.partnerregisternum', 'shop_salesman.validordernum', 'shop_salesman.withdrawalmoney', 'shop_salesman.balance', 'shop_salesman.status', 'shop_salesman.created_at')
                    ->paginate($perpage);
            } else {
                $data = ShopSalesman::where('shop_salesman.type', 'like', $type)
                    ->where('shop_salesman.status', 'like', $status)
                    ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
                    ->where('shops.cityid', $cityid)
                    ->orderBy('shop_salesman.created_at', 'desc')
                    ->select('shop_salesman.id as shopsalesmanid', 'shops.id as shopid', 'shops.code', 'shops.parentmobile', 'shops.name as shopname', 'shops.address', 'shops.qrcode', 'shop_salesman.adminname', 'shop_salesman.type', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime', 'shop_salesman.commonregisternum', 'shop_salesman.partnerregisternum', 'shop_salesman.validordernum', 'shop_salesman.withdrawalmoney', 'shop_salesman.balance', 'shop_salesman.status', 'shop_salesman.created_at')
                    ->paginate($perpage);
            }
        } else {
            //不在南昌的分部
            if ($search) {
                $GLOBALS['search'] = $search;
                $data = ShopSalesman::where('shop_salesman.type', 'like', $type)
                    ->where('shop_salesman.status', 'like', $status)
                    ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
                    ->where('shops.cityid', $cityid)
                    ->where(function ($query) {
                        $query->orWhere('shops.code', 'like', '%' . $GLOBALS . '%')
                            ->orwhere('shops.name', 'like', '%' . $GLOBALS . '%');
                    })
                    ->orderBy('shop_salesman.created_at', 'desc')
                    ->select('shop_salesman.id as shopsalesmanid', 'shops.id as shopid', 'shops.code', 'shops.parentmobile', 'shops.name as shopname', 'shops.address', 'shop_salesman.adminname', 'shop_salesman.type', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime', 'shop_salesman.commonregisternum', 'shop_salesman.partnerregisternum', 'shop_salesman.validordernum', 'shop_salesman.withdrawalmoney', 'shop_salesman.balance', 'shop_salesman.status', 'shop_salesman.created_at')
                    ->paginate($perpage);
            } else {
                $data = ShopSalesman::where('shop_salesman.type', 'like', $type)
                    ->where('shop_salesman.status', 'like', $status)
                    ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
                    ->where('shops.cityid', $cityid)
                    ->orderBy('shop_salesman.created_at', 'desc')
                    ->select('shop_salesman.id as shopsalesmanid', 'shops.id as shopid', 'shops.code', 'shops.parentmobile', 'shops.name as shopname', 'shops.address', 'shop_salesman.adminname', 'shop_salesman.type', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime', 'shop_salesman.commonregisternum', 'shop_salesman.partnerregisternum', 'shop_salesman.validordernum', 'shop_salesman.withdrawalmoney', 'shop_salesman.balance', 'shop_salesman.status', 'shop_salesman.created_at')
                    ->paginate($perpage);
            }
            foreach($data as $k=>$v) {
                $data[$k]['parentmobile'] = str_replace(substr($data[$k]['parentmobile'], 3, 4), '****', $data[$k]['parentmobile']);
            }
        }
        return ['status'=>'success', 'data'=>$data];
    }
    //通过门店登录帐号或商家代码查询商家
    public static function searchShopByCode($cityId, $shopCode) {
        if(!$shopCode || !$cityId) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $data = Shop::where('status', 1)->where('cityid', $cityId)->where('code', $shopCode)
            ->select('id as shopid', 'code as shopcode', 'name as shopname','address', 'cardholder', 'bankcard', 'bankname', 'bankprovince', 'bankcity', 'opencardbank')
            ->first();
        if(!$data) {
            return ['status'=>'failed', 'message'=>'查询失败'];
        }
        return ['status'=>'success', 'data'=>$data];
    }
    //新增地推商家, type为common(普通)， partner(合伙人)
    public static function addShopSalesman($shopId, $cityId, $type, $payFee=0.00, $contractMonth=0,$upgradePassword='') {
        if(!$shopId || !$type || !$cityId) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        if($type == 'partner') {
            if(!$upgradePassword){
                return ['status'=>'failed', 'message'=>'参数错误'];
            }
            if(env('WEB_URL') == 'https://www.fbw-china.com/') {
                if($upgradePassword != 'fbw1984') {
                    return ['status'=>'failed','message'=>'密码错误'];
                }
            } else {
                if($upgradePassword != 'fbw123') {
                    return ['status'=>'failed','message'=>'密码错误'];
                }
            }
            if(!$payFee || ($payFee == 0.00)|| !$contractMonth||($contractMonth==0) ) {
                return ['status'=>'failed', 'message'=>'参数错误'];
            }
        } else {
            $contractMonth = 12;
        }
        $contractStartTime = date('Y-m-d');
        $contractEndTime = date('Y-m-d', strtotime("+". $contractMonth . "months"));
        $oldShopSalesman = ShopSalesman::where('shopid', $shopId)->first();
        if($oldShopSalesman) {
            if($oldShopSalesman->status == '0') {
                return ['status'=>'failed', 'message'=>'该商家的状态是终止，请到列表中修改'];
            }
            return ['status'=>'failed', 'message'=>'该商家已是地推商家'];
        }

        $admin = Shop::where('shops.id', $shopId)
            ->join('admin_users', 'shops.maintainerid', '=', 'admin_users.id')
            ->select('admin_users.realname')->first();
        if($admin) {
            $adminName = $admin->realname;
        } else {
            $adminName = '';
        }
        $shopSalesman = ShopSalesman::create([
            'shopid' => $shopId,
            'type' => $type,
            'payfee' => $payFee,
            'contractmonth' => $contractMonth,
            'contractstarttime' => $contractStartTime,
            'contractlasttime' => $contractEndTime,
            'status' => '1',
            'adminname' => $adminName,
        ]);
        return ['status'=>'success', 'message'=>'新增成功'];
    }
    //修改商家地推状态
    public static function updateShopSalesmanStatus($shopId, $status, $payFee, $type, $contractMonth) {
        if(!$shopId) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        if($status ==1) {
            if(!$type||!$contractMonth) {
                return ['status'=>'failed', 'message'=>'参数错误'];
            }
            $data = [
                'status' => $status,
                'payfee' => $payFee,
                'type' => $type,
                'contractmonth' => $contractMonth,
                'contractstarttime' => date('Y-m-d'),
                'contractlasttime' => date('Y-m-d', strtotime("+".$contractMonth."months"))
            ];
            ShopSalesman::where('shopid', $shopId)->update($data);
        } else {
            ShopSalesman::where('shopid', $shopId)->update(['status' => $status]);
        }
        return ['status'=>'success', 'message'=>'修改成功'];
    }
    //升级商家地推
    public static function upgradeShopSalesman($shopId, $payFee, $contractMonth,$upgradePassword) {
        if(!$shopId||!$payFee||!$contractMonth || !$upgradePassword) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        if(env('WEB_URL') == 'https://www.fbw-china.com/') {
            if($upgradePassword != 'fbw1984') {
                return ['status'=>'failed','message'=>'密码错误'];
            }
        } else {
            if($upgradePassword != 'fbw123') {
                return ['status'=>'failed','message'=>'密码错误'];
            }
        }
        $shopSalesman = ShopSalesman::where('shopid', $shopId)->first();
        if(!$shopSalesman) {
            return ['status'=>'failed', 'message'=>'获取失败'];
        }
        if($shopSalesman->type == 'partner') {
            return ['status'=>'failed', 'message'=>'该商家已是地推合伙人'];
        }
        $shopSalesman->type = 'partner';
        $shopSalesman->payfee = $payFee;
        $shopSalesman->contractmonth = $contractMonth;
        $shopSalesman->save();
        return ['status'=>'success', 'message'=>'修改成功'];
    }
    //商家地推详情
    public static function getShopSalesmanDetail($shopId, $startTime='', $lastTime='') {
        if(!$shopId) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $lists = [];
        $info = ShopSalesman::where('shop_salesman.shopid', $shopId)
            ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
            ->select('shops.name', 'shops.address', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime')
            ->first();
        if (!$startTime || !$lastTime) {
            $detail = ShopSalesmanDetail::where('shopid', $shopId)->select('created_at')->orderBy('created_at', 'asc')->first();
            if($detail) {
                $startTime = strtotime($detail['created_at']);
                $lastTime = time();
                $interval = round(($lastTime-$startTime)/3600/24);
                for ($i = 0; $i <= $interval; $i++) {
                    $day = date("Y-m-d", strtotime('-' . $i . 'days'));
                    $dayStartTime = $day . " 00:00:00";
                    $dayEndTime = $day . " 23:59:59";
                    $registerNum = ShopSalesmanDetail::where('shopid', $shopId)
                        ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                        ->where('type', 'register')
                        ->get()->count();
                    $validRegisterNum = ShopSalesmanDetail::where('shopid', $shopId)
                        ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                        ->where('type', 'register')->where('getmoney', '!=', 0)
                        ->get()->count();
                    $orderNum = ShopSalesmanDetail::where('shopid', $shopId)
                        ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                        ->where('type', 'order')
                        ->get()->count();
                    $validOrderNum = ShopSalesmanDetail::where('shopid', $shopId)
                        ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                        ->where('type', 'order')
                        ->where('getmoney', '<>', 0)
                        ->get()->count();
                    $orderAmount = ShopSalesmanDetail::where('shopid', $shopId)
                        ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                        ->where('type', 'order')->where('getmoney', '<>', 0)
                        ->sum('orderamount');
                    $getMoney = ShopSalesmanDetail::where('shopid', $shopId)
                        ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                        ->sum('getmoney');
                    if (($registerNum != 0) || ($validOrderNum != 0)) {
                        array_push($lists, [
                            'date' => $day,
                            'registernum' => $registerNum,
                            'validregisternum' => $validRegisterNum,
                            'ordernum' => $orderNum,
                            'validordernum' => $validOrderNum,
                            'orderamount' => $orderAmount,
                            'getmoney' => $getMoney
                        ]);
                    }
                }
            }
        } else {
            if($lastTime<$startTime) {
                return ['status' => 'failed', 'message' => '起始时间错误！'];
            }
            $interval = round(($lastTime-$startTime)/3600/24);
            for($i = 0;$i <= $interval;$i ++) {
                $day = date("Y-m-d", $lastTime- strtotime("-".$i."days"));
                $dayStartTime =  $day. " 00:00:00";
                $dayEndTime =  $day. " 23:59:59";
                $registerNum = ShopSalesmanDetail::where('shopid', $shopId)
                    ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                    ->where('type', 'register')
                    ->get()->count();
                $validRegisterNum = ShopSalesmanDetail::where('shopid', $shopId)
                    ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                    ->where('type', 'register')->where('getmoney', '!=', 0)
                    ->get()->count();
                $orderNum = ShopSalesmanDetail::where('shopid', $shopId)
                    ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                    ->where('type', 'order')
                    ->get()->count();
                $validOrderNum = ShopSalesmanDetail::where('shopid', $shopId)
                    ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                    ->where('type', 'order')
                    ->where('getmoney', '<>', 0)
                    ->get()->count();
                $orderAmount = ShopSalesmanDetail::where('shopid', $shopId)
                    ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                    ->where('type', 'order')
                    ->sum('orderamount');
                $getMoney = ShopSalesmanDetail::where('shopid', $shopId)
                    ->where('created_at', '>=', $dayStartTime)->where('created_at', '<=', $dayEndTime)
                    ->sum('getmoney');
                if(($registerNum != 0) || ($validOrderNum != 0)) {
                    array_push($lists, [
                        'date' => $day,
                        'registernum' => $registerNum,
                        'validregisternum' => $validRegisterNum,
                        'ordernum' => $orderNum,
                        'validordernum' => $validOrderNum,
                        'orderamount' => $orderAmount,
                        'getmoney' => $getMoney
                    ]);
                }
            }
        }
        $data = [
            'lists' => $lists,
            'info' => $info
        ];
        return ['status' => 'success','data'=>$data];
    }
    //商家地推注册详情
    public static function getShopSalesmanRegisterDetail($shopId, $startTime, $perpage=20) {
        if(!$shopId||!$startTime) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $info = ShopSalesman::where('shop_salesman.shopid', $shopId)
            ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
            ->select('shops.name', 'shops.address', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime')
            ->first();
        $dayStartTime = $startTime . " 00:00:00";
        $dayEndTime = $startTime . " 23:59:59";
        $lists = ShopSalesmanDetail::where('shop_salesman_detail.shopid', $shopId)
            ->where('shop_salesman_detail.type', 'register')
            ->where('shop_salesman_detail.created_at', '>=' , $dayStartTime)
            ->where('shop_salesman_detail.created_at', '<=', $dayEndTime)
            ->join('users', 'shop_salesman_detail.mobile', '=', 'users.mobile')
            ->select('shop_salesman_detail.id', 'shop_salesman_detail.created_at', 'shop_salesman_detail.mobile', 'shop_salesman_detail.registersource',
                'shop_salesman_detail.shopusermobile', 'shop_salesman_detail.getmoney', 'users.id as userid')
            ->paginate($perpage);
        foreach($lists as $k=>$v) {
            $lists[$k]['ordernum'] = Order::where('userid', $lists[$k]['userid'])->count();
            $lists[$k]['validordernum'] = ShopSalesmanDetail::where('mobile', $lists[$k]['mobile'])->where('type', 'order')->count();
            $lists[$k]['orderamount'] = ShopSalesmanDetail::where('mobile', $lists[$k]['mobile'])->where('type', 'order')->sum('orderamount');
            $lists[$k]['mobile'] = str_replace(substr($lists[$k]['mobile'], 3, 4), '****', $lists[$k]['mobile']);
        }
        $data = [
            'lists' => $lists,
            'info' => $info
        ];
        return ['status'=>'success', 'data'=>$data ];
    }
    //导出商家地推注册详情
    public static function exportShopSalesmanRegister($shopId, $startTime) {
        if(!$shopId||!$startTime) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $dayStartTime = $startTime . " 00:00:00";
        $dayEndTime = $startTime . " 23:59:59";
        $data = ShopSalesmanDetail::where('shop_salesman_detail.shopid', $shopId)->where('shop_salesman_detail.type', 'register')
            ->where('shop_salesman_detail.created_at', '>=' , $dayStartTime)->where('shop_salesman_detail.created_at', '<=', $dayEndTime)
            ->join('users', 'shop_salesman_detail.mobile', '=', 'users.mobile')
            ->select('shop_salesman_detail.created_at', 'shop_salesman_detail.mobile', 'shop_salesman_detail.registersource', 'shop_salesman_detail.shopusermobile', 'shop_salesman_detail.getmoney', 'users.id as userid')
            ->get();
        foreach($data as $k=>$v) {
            $data[$k]['ordernum'] = Order::where('userid', $data[$k]['userid'])->count();
            $data[$k]['validordernum'] = ShopSalesmanDetail::where('mobile', $data[$k]['mobile'])->where('type', 'order')->count();
            $data[$k]['orderamount'] = ShopSalesmanDetail::where('mobile', $data[$k]['mobile'])->where('type', 'order')->sum('orderamount');
            $data[$k]['mobile'] = str_replace(substr($data[$k]['mobile'], 3, 4), '****', $data[$k]['mobile']);
        }
        return ['status'=>'success', 'data'=>$data ];
    }
    //商家地推有效订单详情
    public static function getShopSalesmanValidOrderDetail($shopId, $startTime, $perpage=20) {
        if(!$shopId||!$startTime) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $info = ShopSalesman::where('shop_salesman.shopid', $shopId)
            ->join('shops', 'shop_salesman.shopid', '=', 'shops.id')
            ->select('shops.name', 'shops.address', 'shop_salesman.payfee', 'shop_salesman.contractmonth', 'shop_salesman.contractstarttime', 'shop_salesman.contractlasttime')
            ->first();
        $dayStartTime = $startTime . " 00:00:00";
        $dayEndTime = $startTime . " 23:59:59";
        $lists = ShopSalesmanDetail::where('shop_salesman_detail.shopid', $shopId)
            ->where('shop_salesman_detail.type', 'order')
            ->where('shop_salesman_detail.created_at', '>=' , $dayStartTime)
            ->where('shop_salesman_detail.created_at', '<=', $dayEndTime)
            ->join('orders', 'shop_salesman_detail.ordernumber', '=', 'orders.ordernumber')
            ->join('shops', 'orders.shopid', '=', 'shops.id')
            ->select('shop_salesman_detail.id', 'shop_salesman_detail.ordernumber','shop_salesman_detail.orderamount',
                'shop_salesman_detail.ordertime','shop_salesman_detail.created_at', 'shop_salesman_detail.mobile',
                'shop_salesman_detail.registersource', 'shop_salesman_detail.shopusermobile', 'shop_salesman_detail.getmoney',
                'shops.code as shopcode', 'shops.name as shopname'
            )
            ->paginate($perpage);
        foreach($lists as $k=>$v) {
            $lists[$k]['mobile'] = str_replace(substr($lists[$k]['mobile'], 3, 4), '****', $lists[$k]['mobile']);
        }
        $data = [
            'lists' => $lists,
            'info' => $info
        ];
        return ['status'=>'success', 'data'=>$data ];
    }
    //导出商家地推有效订单详情
    public static function exportShopSalesmanValidOrderDetail($shopId, $startTime) {
        if(!$shopId||!$startTime) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $dayStartTime = $startTime . " 00:00:00";
        $dayEndTime = $startTime . " 23:59:59";
        $data = ShopSalesmanDetail::where('shop_salesman_detail.shopid', $shopId)->where('shop_salesman_detail.type', 'order')
            ->where('shop_salesman_detail.created_at', '>=' , $dayStartTime)->where('shop_salesman_detail.created_at', '<=', $dayEndTime)
            ->join('orders', 'shop_salesman_detail.ordernumber', '=', 'orders.ordernumber')
            ->join('shops', 'orders.shopid', '=', 'shops.id')
            ->select('shop_salesman_detail.ordernumber','shop_salesman_detail.orderamount','shop_salesman_detail.ordertime',
                 'shop_salesman_detail.mobile', 'shop_salesman_detail.getmoney', 'shops.name as shopname', 'shops.code as shopcode')
            ->get();
        foreach($data as $k=>$v) {
            $data[$k]['mobile'] = str_replace(substr($data[$k]['mobile'], 3, 4), '****', $data[$k]['mobile']);
        }
        return ['status'=>'success', 'data'=>$data];
    }
    //结款金额
    public static function getShopSalesmanWithdrawalDetail($shopId, $perpage = 20) {
        if(!$shopId) {
            return ['status'=>'failed', 'message'=>'参数不对'];
        }
        $info = Shop::where('id', $shopId)->select('cardholder', 'bankname', 'bankcard', 'bankprovince', 'bankcity', 'opencardbank')->first();
        $lists = ShopSalesmanWithdrawal::where('shopid', $shopId)->where('status', 1)
            ->select('id', 'accounttime', 'accountamount', 'balance', 'created_at')
            ->orderBy('created_at', 'desc')
            ->paginate($perpage);
        $data = [
            'info' => $info,
            'lists' => $lists
        ];
        return ['status'=>'success', 'data'=>$data];
    }
    //某个人的地推订单
    public static function personSalesmanOrderLists($userId, $page=1, $length=10) {
        if(!$userId) {
            return ['status'=>'failed', 'message'=>'参数错误'];
        }
        $skip = ($page-1)*$length;
        $mobile = User::where('id', $userId)->pluck('mobile')->first();
        $shopUserMobile = ShopSalesmanDetail::where('type', 'order')->where('mobile', $mobile)->pluck('shopusermobile')->first();
        if(!$shopUserMobile) {
            $shopUserMobile = '';
            $shopUserName = '';
        } else {
            $shopUserName = ShopUser::where('mobile', $shopUserMobile)->pluck('name')->first();
            $shopUserName = (!$shopUserName)? '': $shopUserName;
        }
        $count = ShopSalesmanDetail::where('type', 'order')->where('mobile', $mobile)->get()->count();
        $lists = ShopSalesmanDetail::where('type', 'order')->where('mobile', $mobile)
            ->select('created_at', 'ordernumber', 'orderamount')
            ->skip($skip)->take($length)->get();
        $data = [
            'name' => $shopUserName,
            'mobile' => $shopUserMobile,
            'count' => $count,
            'lists' => $lists
        ];
        return ['status'=>'success', 'data'=>$data];
    }
}